package com.ruoyi.business.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.vo.BusHiddenRiskVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusHiddenRisk;
import com.ruoyi.business.service.IBusHiddenRiskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 待处理隐患台账Controller
 * 
 * @author ling
 *  2024-07-24
 */
@RestController
@RequestMapping("/business/risk")
public class BusHiddenRiskController extends BaseController
{
    @Resource
    private IBusHiddenRiskService busHiddenRiskService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询待处理隐患台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:risk:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusHiddenRisk busHiddenRisk)
    {
        startPage();
        List<BusHiddenRiskVo> list = busHiddenRiskService.selectBusHiddenRiskVoList(busHiddenRisk);
//        list.forEach(System.out::println);
        return getDataTable(list);
    }
    /**
     * 查询确认隐患台账列表
     */
//    @PreAuthorize("@ss.hasPermi('/business/risk/confirmlist')")
    @GetMapping("/confirmlist")
    public TableDataInfo ConfirmList(BusHiddenRisk busHiddenRisk)
    {
        startPage();
        List<BusHiddenRiskVo> list = busHiddenRiskService.selectBusHiddenRiskVoConfirmList(busHiddenRisk);
//        list.forEach(System.out::println);
        return getDataTable(list);
    }

    /**
     * 导出待处理隐患台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:risk:export')")
    @Log(title = "待处理隐患台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusHiddenRisk busHiddenRisk)
    {
        List<BusHiddenRisk> list = busHiddenRiskService.selectBusHiddenRiskList(busHiddenRisk);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusHiddenRisk> util = new ExcelUtil<>(BusHiddenRisk.class);
        util.exportExcel(response, list, "待处理隐患台账数据");
    }

    /**
     * 获取待处理隐患台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:risk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busHiddenRiskService.selectBusHiddenRiskById(id));
    }

    /**
     * 新增待处理隐患台账
     */
    @PreAuthorize("@ss.hasPermi('business:risk:add')")
    @Log(title = "待处理隐患台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusHiddenRisk busHiddenRisk)
    {
        return toAjax(busHiddenRiskService.insertBusHiddenRisk(busHiddenRisk));
    }

    /**
     * 修改待处理隐患台账
     */
    @PreAuthorize("@ss.hasPermi('business:risk:confirm')")
    @Log(title = "待处理隐患台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusHiddenRisk busHiddenRisk)
    {
        return toAjax(busHiddenRiskService.updateBusHiddenRisk(busHiddenRisk));
    }

    /**
     * 删除待处理隐患台账
     */
    @PreAuthorize("@ss.hasPermi('business:risk:remove')")
    @Log(title = "待处理隐患台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busHiddenRiskService.deleteBusHiddenRiskByIds(ids));
    }
}
